﻿;_____________________________________________________________________
;---------------------------------------------------------------------
;	File: PML_EFD-EDS
;---------------------------------------------------------------------
;	Handles actions related to the EFD and EDS tools. Quickly view, create
;	and edit documents with ease.
;
;
;	EFD Manager:
;
;		Effortlessly create (as designer), complete (as checker), print or view EFD checklists from a simple interface; files are controlled and managed so that you can easily see the status of a given RTA/EFD
;
;		(See PML_ScreenShot-EFD.png)
;
;	EDS Manager:
;
;		Automatically generate, edit, view, print and upload Engineering Data Sheets for parts through a simple interface; look up thread connection data with 1 click if needed before beginning a new EDS. Files are managed and tracked so that you can see that status/view a part's EFD by simply enter it's reference number.
;
;		(see PML_ScreenShot-EDS.png)
;
;	Group: About
;		General script file information
;
;		- *Written By:* 	Rameen Bakhtiary
;		- *Last Modified:*	11/30/2011
;_____________________________________________________________________
;---------------------------------------------------------------------





;=================================================================
;                      EFD / EDS  BUTTON HANDLER
;
;	Enables and disables the buttons (new, edit, open, etc.) on 
;	the EFD & EDS GUIs according to the current input number.
;=================================================================
	PMF_buttonDisabler:
		Gui, Submit, NoHide
		If % %A_GuiControl%=efdRTAnum
		{
			efdGUI:=True
			edsGUI:=False
			maxLen:=6
		}
		If % %A_GuiControl%=mndAssyNum
		{
			efdGUI:=False
			edsGUI:=True
			maxLen:=9
		}
		if !A_GuiControl
			return
		StringLen, len, %A_GuiControl%
		
		
		
		
		;=================================================================
		;                    LENGTH VALID... LOOK FOR FILE
		;=================================================================
		If len=%maxLen%
		{									
			
			;_____________________________ E D S   B U T T O N   H A N D L E R _________________________________
			;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
						
			
			If edsGUI
			{
				;Check macro version files
				IfExist, %EDSedit_Dir%\%mndAssyNum%.xlsm
				{
					GuiControl, 4:Show, button3
					GuiControl, 4:Enable, button3
					GuiControl, 4:Hide, button2
					GuiControl, 4:Hide, button1
					GuiControl, 4:Hide, button5
					mac=1
				}
				Else
				{
					GuiControl, 4:Hide, button3
					mac=
				}
				;Check Standard xlsx files
				IfExist, %EDSview_Dir%\%mndAssyNum%.xlsx
				{
					WinMove, Mandrel EDS,,,,,140
					GuiControl, 4:Show, button4
					GuiControl, 4:Enable, button4
					GuiControl, 4:Hide, button2
					GuiControl, 4:Hide, button1			
					GuiControl, 4:Show, button5
					GuiControl, 4:Enable, button5
					Clipboard=
					Clipboard=%EDSview_Dir%\%mndAssyNum%.xlsx
					std=1
				}
				Else
				{
					WinMove, Mandrel EDS,,,,,103
					GuiControl, 4:Hide, button4
					GuiControl, 4:Hide, button5
					std=
				}
				;File doesn't exist
				If (!mac && !std)
				{
					WinMove, Mandrel EDS,,,,,103
					GuiControl, 4:Show, button1
					GuiControl, 4:Show, button2
					GuiControl, 4:Enable, button2
					GuiControl, 4:Hide, button3
					GuiControl, 4:Hide, button4
					GuiControl, 4:Hide, button5
				}
			}
			
			
			
			
			;_____________________________ E D S   B U T T O N   H A N D L E R _________________________________
			;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
			
			If efdGUI
			{
				IfExist, %EFDchecking_Dir%\%efdRTAnum%.docm
				{
					GuiControl, 3:Show, button2
					GuiControl, 3:Enable, button2
					GuiControl, 3:Hide, button1
					GuiControl, 3:Hide, button3
					des=1
				}
				Else
				{
					GuiControl, 3:Hide, button2
					des=
				}
				
				IfExist, %EFDdone_Dir%\%efdRTAnum%.docm
				{
					GuiControl, 3:Show, button3
					GuiControl, 3:Enable, button3
					GuiControl, 3:Hide, button2
					GuiControl, 3:Hide, button1
					chkd=1
				}
				Else
				{
					GuiControl, 3:Hide, button3
					chkd=
				}			

				If (!des && !chkd)
				{
					GuiControl, 3:Show, button1
					GuiControl, 3:Enable, button1
					GuiControl, 3:Hide, button2
					GuiControl, 3:Hide, button3
				}
			}
			Return
		}
		;Re-Disable All On change
		If efdGUI
		{
			GuiControl, 3:Show, button1
			GuiControl, 3:Show, button2
			GuiControl, 3:Show, button3
			GuiControl, 3:Disable, button1
			GuiControl, 3:Disable, button2
			GuiControl, 3:Disable, button3
		}
		If edsGUI
		{
			WinMove, Mandrel EDS,,,,,103
			GuiControl, 4:Hide, button1
			GuiControl, 4:Hide, button5
			GuiControl, 4:Show, button2
			GuiControl, 4:Show, button3
			GuiControl, 4:Show, button4
			GuiControl, 4:Disable, button2
			GuiControl, 4:Disable, button3
			GuiControl, 4:Disable, button4
		}
	Return
	
	
	
	
	
	
	
;________________________________________ Routines -- EDS __________________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%	
	




;===================================================
;								NEW  EDS
;===================================================
	Create_New_EDS:
		Gui, 4:Submit
		Gui, 4:Destroy 
		Gosub, 4guiclose
		Gui, 1:Destroy			
		If (threadinfo){		;Get thread info before creating EDS
			If !(FileExist("Include\Threads\threads.exe")){
				error_handle("missing", "Threads.exe")
				Return
			}
			RunWait, Include\Threads\threads.exe
		}
		Run, %EDSFILE%
		WinWait, Mandrel Reference Number
		ControlSend, edit1, %mndAssyNum%{Enter}, Mandrel Reference Number
	Return


;===================================================
;							VIEW COMPLETE EDS
;===================================================
	openStdEDS:
		Gui, 4:Submit
		Gui, 4:Destroy
		Gosub, 4guiclose
		Gui, 1:Destroy
		Run, %EDSview_Dir%\%mndAssyNum%.xlsx
	Return


;===================================================
;								EDIT  EDS
;===================================================
	Edit_an_existing_EDS:
		Gui, 4:Submit
		Gui, 4:Destroy
		Gosub, 4guiclose
		Gui, 1:Destroy	
		Run, %EDSedit_Dir%\%mndassynum%.xlsm
	Return



;===================================================
;								LOAD EDS TO CWI
;===================================================
copyCWIpath:
	gui, 4:destroy
	Gosub, 4guiclose
	n:=0
	settimer, ttDisp, 200
	guiclose:
	GuiEscape:
	GUI, 1:DESTROY
	GUI, 2:DESTROY
return




;________________________________________ Routines -- EFD __________________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%



;===================================================
;								NEW  EFD
;===================================================
	Create_New_EFD:
		Gui, 3:Submit	
		Gui, 3:Destroy
		Gosub, 3guiclose
		Gui, 1:Destroy			
		Run, % EFDFILE
		WinWait, Microsoft Word, RTA Number
		sleep 200
		ControlSend, Edit1, %efdRTAnum%{Enter}, Microsoft Word
	Return



;===================================================
;			COMPLETE EFD - CHECKER
;===================================================
	Complete_EFD_as_Checker:
		Gui, 3:Submit	
		Gui, 3:Destroy
		Gosub, 3guiclose
		Gui, 1:Destroy
		Run, %EFDchecking_Dir%\%efdRTAnum%.docm
	Return



;===================================================
;			VIEW COMPLETE EFD
;===================================================
	View_/_Re-Print_completed_EFD:
		Gui, 3:Submit	
		Gui, 3:Destroy
		Gosub, 3guiclose
		Gui, 1:Destroy
		Run, %EFDdone_Dir%\%efdRTAnum%.docm
	Return





;________________________________________ Helper Routines __________________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%




;=================================================================
;	PLACES CURSOR AT RIGHT OF EDIT BOX AFTER IT GETS AUTO-FILLED
;=================================================================
Rightcurs:
	If WinExist("Edit an EDS"){
		SetTimer, rightcurs, Off
		Send, {Right}
	}
Return



;===================================================
;		SHOW TOOLTIP WHEN 'LOAD TO CWI' CLICKED
;===================================================
ttDisp:
	MouseGetPos, mx, my	
	mx:= mx-295
	my:=my-50
	ToolTip, The EDS filepath is copied to your clipboard.`n`nOpen the CWI file window and paste into "File Checkin",%mx%, %my%
	n++
	if n>15
	{
		settimer, ttdisp, off
		ToolTip
	}
return






